/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package job.manager.site.mb.security;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import com.icesoft.faces.component.ext.HtmlCommandButton;
import job.manager.core.db.UsersEB;
import job.manager.core.ex.UserNotFoundException;
import job.manager.core.sb.UserRemote;

/**
 *
 * @author Administrator
 */

public class LoginManagedBean {
    @EJB
    private UserRemote userBean;

    private String username;
    private String password;
    private String errorMsg;

    /** Creates a new instance of LoginManagedBean */
    public LoginManagedBean() {
    }

    @PostConstruct
    public void init() {
        this.username = "";
        this.password = "";
        this.errorMsg = "";
    }

    /** Action Listeners of LoginManagedBean */

    public void LoginAction(ActionEvent event) throws AbortProcessingException {
        if( event.getComponent() instanceof HtmlCommandButton ) {
            HtmlCommandButton b = (HtmlCommandButton) event.getComponent();
            try {
                UsersEB user = userBean.login(username, password);
            }catch(UserNotFoundException ex) {
                this.errorMsg = ex.getMessage();
            }
        }
    }

    /** Setter and Getters of LoginManagedBean */
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }
    
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }
}
